//
//  YDBaseViewController.swift
//  weibo
//
//  Created by 孙亚东 on 16/6/23.
//  Copyright © 2016年 Sunyadong. All rights reserved.
//

import UIKit
import SVProgressHUD

class YDBaseViewController: UITableViewController {
    
    //定义一个bool类型的变量，由于确定View的类型
    
    var isLogin: Bool = YDOauthViewModel.shareOauthViewModel.isLogin
    
    let logInView = YDLogInView()

    override func viewDidLoad() {
        super.viewDidLoad()

        
   
        
    }
    
    

    override func loadView() {
        
        if isLogin {
            
            
            super.loadView()
        
    
        }else{
      
            self.view = logInView
            
            setupNaviBtn()
            
            logInView.delegate = self
            
            

        }

    }
    
    
    // 添加navigation
    func setupNaviBtn () {
    
        navigationItem.rightBarButtonItem = UIBarButtonItem.init(title: "注册", style: .Plain, target: self, action: "registerMethod")
        
    
    
        navigationItem.leftBarButtonItem = UIBarButtonItem.init(title: "登录", style: .Plain, target: self, action: "loginMethod")
    
    
    }
    

    
    

}

extension YDBaseViewController: YDLogInViewDelegate{
    
    func loginMethod() {
        
        
        //实现登录功能
        print("实现登录功能")
        
        // 弹出登录界面
        
        let naviVC = UINavigationController(rootViewController: YDLogViewController())
        
        presentViewController(naviVC, animated: true, completion: nil)
        
    }
    
    
    
    func registerMethod() {
        
        
        //实现注册功能
        print("实现注册功能")
        
    }
    
    
    
    
}


extension YDBaseViewController {


    func showProgress () {
    
        SVProgressHUD.show()
    
    
    }
    
    func hiddenProgress () {
    
    
        SVProgressHUD.dismiss()
    
    
    }
    
    func showErrorProgress (str: String?) {
    
        
        SVProgressHUD.showErrorWithStatus(str)
    
    }




}